package com.xy.mainp.base;

import android.content.Context;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

import com.xy.base.BaseFragment;

/**
 * Created by John on 2016/11/21.
 */

public class OneCreateFragment extends BaseFragment implements View.OnTouchListener {

    private Context mContext;
    private boolean isCreate;
    protected View ConverView;
    private SparseArray<View> mViews;

    @Override
    public void onAttach(Context context) {
        this.mContext = context;
        super.onAttach(context);
    }

    @Override
    public Context getContext() {
        Context context = super.getContext();
        if (context == null){
            return mContext;
        }
        return super.getContext();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (isCreate){
            onCreateOneTime(savedInstanceState);
        }
        isCreate = false;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return convertView;
    }

    public View setContentView(int id) {
        return setContentView(LayoutInflater.from(getContext()).inflate(id, null, false));
    }

    public View setContentView(View view) {
        mViews = new SparseArray<>();
        convertView = view;
        if (convertView != null){
            convertView.setOnTouchListener(this);
        }
        return convertView;
    }

    public void onCreateOneTime(Bundle savedInstanceState) {

    }

    public View getRootView() {
        return convertView;
    }



    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        return true;
    }
}
